<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class CommonForm extends Model
{
    protected $table = 'common_form';
    protected $fillable = [
        'title','content','uid','type'
    ];
    const TYPE_WORK = 1;
    const TYPE_FUNCTIONS = 2;
    public static $typeNames = [
        1=>'工作须知',2=>'常用功能'
    ];

    public function staff()
    {
        return $this->belongsTo(OAStaff::class,'uid');
    }

    public function files()
    {
        return $this->hasMany(OAFiles::class,'pid')->where('type',FILE_COMMON_FORM);
    }

    public function getTypeNameAttribute($type)
    {
        return self::$typeNames[$type] ?? self::$typeNames[self::TYPE_WORK];
    }
}
